package com.qianbao.service.money.impl;

import com.qianbao.components.excepion.CommonException;
import com.qianbao.components.excepion.ExceptionEnum;
import com.qianbao.dao.money.ReadTimeDao;
import com.qianbao.service.money.ReadTimeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class ReadTimeServiceImpl implements ReadTimeService {

    @Autowired
    private ReadTimeDao dao;

    @Override
    public void saveUserReadTime(String customId, String readTime) throws CommonException {

        if (customId == null || customId.length() == 0
                || readTime == null || readTime.length() == 0){
            throw new CommonException(ExceptionEnum.Request_Params_Invalid.getCode(),
                    ExceptionEnum.Request_Params_Invalid.getMessage());
        }

        int rows = dao.saveUserReadTime(customId, Integer.parseInt(readTime));

        if (rows <= 0){
            throw new CommonException(ExceptionEnum.Sql_update_fail.getCode(),
                    ExceptionEnum.Sql_update_fail.getMessage());
        }

    }

    @Override
    public int findUserReadTime(String customId) throws CommonException {
        if (customId == null || customId.length() == 0){
            throw new CommonException(ExceptionEnum.Request_Params_Invalid.getCode(),
                    ExceptionEnum.Request_Params_Invalid.getMessage());
        }
        int time = dao.findUserReadTime(customId);
        return time;
    }



}
